<?python 
import datetime, time 
from kisp import *
from actions import *

if new:
	submit_url = url('/trigger_add/%s/' % tag.id)
else:
	submit_url = url('/trigger_edit/%s/'% trigger.id)
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:xi="http://www.w3.org/2001/XInclude"
	  xmlns:py="http://genshi.edgewall.org/">
  <xi:include href="layout.html" />
  <head>
  <title>Edit Trigger For ${tag.title}</title>
  </head>
  <body class="poll">
  			<div id="center_column_item">
			
			<H2>Edit Trigger For ${tag.title}</H2>

		<form xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:py="http://genshi.edgewall.org/"
	  class="trigger" trigger="${submit_url}" method="post">
		
		<input type="text" id="trigger_id" name="trigger_id" style="display:none"/>
		<input type="text" id="tag_id" name="tag_id" style="display:none" />
		
		
		<table>
			<tr><th><label for="description">Description:</label></th><td>
			<input type="text" id="description" name="description"/>
			<span py:if="'description' in errors" class="error">${errors.description}</span>
			</td></tr>
			<tr><th><label for="timing">Timing (Minutes):</label></th><td>
			<input type="text" id="timing" name="timing" />
			<span py:if="'timing' in errors" class="error">${errors.timing}</span>
			</td></tr>
			
			<tr><th><label for="action">Action:</label></th><td>
			<select id="action" name="action" onchange="$('.trigger_arguments').hide(); $('#' + this.value).show() ;">
				<span py:for="action in KISP.plugins">
					<option py:if="action.Type == 'Action'" value="${action.Name}">${action.Name} - ${action.Description}</option>
				</span>
			</select>
			<span py:if="'action' in errors" class="error"><br />${errors.action}</span>
			</td></tr>
			<tr><th><label for="arguments">Arguments:</label></th><td>
			<input type="text" id="arguments" name="arguments"/>
			<span py:if="'arguments' in errors" class="error">${errors.arguments}</span>
			<div py:for="action in KISP.plugins">
				<span py:if="action.Type == 'Action'" class="action_arguments" id="${action.Name}">${action.Arguments}</span>
			</div>
			
			</td></tr>
			<tr><th></th><td>
			<input type="submit" value="Submit" /><input type="submit" id="cancel" name="cancel" value="Cancel" />
			</td></tr>	
		</table>
		
	</form>
		</div>
<script py:if="not new" type="text/javascript">
  $(document).ready(function(){
	$("#trigger_id").val("${trigger.id}");
	$("#tag_id").val("${tag.id}");
    $("#description").val("${trigger.description}");
	$("#timing").val("${'%d'%trigger.timing}");
	$("#action").val("${trigger.action}");
	$("#arguments").val("${trigger.arguments}");
	$(".trigger_arguments").hide();
	$("#${trigger.action}").show(); 
  });  
</script>

<script py:if="new" type="text/javascript">
  $(document).ready(function(){
	$(".trigger_arguments").hide();
	$("#" + $("#action").val()).show();
	$("#tag_id").val("${tag.id}");
  });  
</script>

  </body>
</html>
